//数据库空白检查
function checkEmpty(val) {
	if (typeof (val) == "undefined" || val == '' || val == null) {
		return true;
	}
	return false;
}

//json对象转url地址传参
function jsonTourlparams(object) {
	var str = '';
	for (var key in object) {
		str = str + key + '=' + object[key] + '&';
	}
	return str.substring(0, str.length - 1);
}

//发送验证码
function countdownTime(t, dom) {
	var m = t;
	var infor = document.getElementById(dom);
	infor.innerHTML = m + '秒后重试';
	var timer = setInterval(function() {
		if (m === 0) {
			clearTimeout(timer)
			infor.innerHTML = '重新发送';
			return;
		}
		m--;
		infor.innerHTML = m + '秒后重试';
	}, 1000);
}

function getDateTime() {
	var now = new Date();
	var year = now.getFullYear(); //得到年份
	var month = now.getMonth() + 1;//得到月份
	var date = now.getDate();//得到日期
	// var day = now.getDay();//得到周几
	var hour = now.getHours();//得到小时数
	var minute = now.getMinutes();//得到分钟数
	var second = now.getSeconds();//得到秒数
	return year + '-' + month + '-' + date + ' ' + hour + ':' + minute + ':' + second;
}

//获取当前时间的毫秒
function getTimeMs() {
	var t = new Date();
	return t.getTime();
}

//把毫秒的日期时间，转成形如2019-02-28
function formattingDate(date) {
	var t = new Date(date)
	var y = t.getFullYear()
	var m = t.getMonth() + 1
	m = m < 10 ? '0' + m : m
	var d = t.getDate()
	d = d < 10 ? '0' + d : d
	var str = y + '-' + m + '-' + d
	return str
}

//把毫秒的日期时间，转成形如2019-02-28  减去或者加几年
function formattingDate2(date, type) {
	var t = new Date(date)
	var y = t.getFullYear() + type
	var m = t.getMonth() + 1
	m = m < 10 ? '0' + m : m
	var d = t.getDate()
	d = d < 10 ? '0' + d : d
	var str = y + '-' + m + '-' + d
	return str
}

//按个数对数组进行截取，返回新数组
function chooseArrNumber(arr, num) {
	var array = [];
	var yushu = arr.length % num;
	if (yushu === 0) {
		var n = parseInt(arr.length / num);
	} else {
		var n = parseInt(arr.length / num) + 1;
	}
	for (var i = 0; i < n; i++) {
		array[i] = arr.slice(i * num, (i + 1) * num);
	}
	return array;
}

//毫秒时间获取小时和分
function getTimeHM(t) {
	var date = new Date(t);
	var h = date.getHours() > 12 ? date.getHours() - 12 : date.getHours();
	h = h < 10 ? "0" + h : "" + h;
	var m = date.getMinutes();
	m = m < 10 ? "0" + m : "" + m;

	return h + ':' + m;
}

//毫秒转天时小时毫秒
function getTimeDHMS(t) {
	function checkTime(i) { //将0-9的数字前面加上0，例1变为01 
		if (i < 10) {
			i = "0" + i;
		}
		return i;
	}
	var days = parseInt(t / 1000 / 60 / 60 / 24, 10); //计算剩余的天数 
	var hours = parseInt(t / 1000 / 60 / 60 % 24, 10); //计算剩余的小时 
	var minutes = parseInt(t / 1000 / 60 % 60, 10);//计算剩余的分钟 
	var seconds = parseInt(t / 1000 % 60, 10);//计算剩余的秒数 
	days = checkTime(days);
	hours = checkTime(hours);
	minutes = checkTime(minutes);
	seconds = checkTime(seconds);

	return days + "天" + hours + "小时" + minutes + "分" + seconds + "秒";
}

//文字信息处理超过110加...
function changeStr(txt) {
	if (txt.length > 110) {
		//return txt.slice(0,106)+'...'
		return txt
	} else {
		return txt
	}
}
function changeStr2(txt, n) {
	if (txt.length > n) {
		return txt.slice(0, n) + '...'
	} else {
		return txt
	}
}

//获取url相应参数值
function getQueryString(name) {
	var url = location.search; //获取url中"?"符后的字串 
	var theRequest = new Object();
	if (url.indexOf("?") != -1) {
		var str = url.substr(1);
		strs = str.split("&");
		for (var i = 0; i < strs.length; i++) {
			theRequest[strs[i].split("=")[0]] = unescape(strs[i].split("=")[1]);
		}
	}
	return theRequest[name];
}

//发送验证码
function countdownTime(t, dom) {
	var m = t;
	var infor = document.getElementById(dom);
	infor.innerHTML = m + '秒后重试';
	var timer = setInterval(function() {
		if (m === 0) {
			clearTimeout(timer)
			infor.innerHTML = '重新发送';
			$('.validata a').css('color', '#0092ee').attr('id', 'sendCode');
			return m;
		}
		m--;
		infor.innerHTML = m + '秒后重试';
		$('#sendCode').css('color', '#CBCBCB').removeAttr('id');
	}, 1000);
}

